<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>新品有戏后台管理</title>
    <link href="__CSS__/boot.css" rel="stylesheet">
    <link href="__STATIC__/layui/css/layui.css" rel="stylesheet">
    <script src="__JS__/jquery.js"></script>
    <script src="__JS__/layer/layer.js"></script>
    <script src="__STATIC__/layui/layui.js"></script>
    <style>
        th{
            text-align: center;
            vertical-align: middle!important;
        }
    </style>
</head>
<body>
{include file="base/header" /}
<div style="height: 1px"></div>
<button onclick="purchase({$bid})" type="button" class="layui-btn layui-btn-normal">申请采购</button>
<button type="button" onclick="product({$bid})" class="layui-btn">添加商品</button>
<div style="float: right; margin-top: 5px;margin-bottom: 5px" class="box-title ">
    <form class="form-inline" action="{:url('index/order/goods')}" method="get">
        <input type="hidden" name="id" value="{$bid}"/>
        <input type="text" name="title" value="<?php if(isset($title)) echo $title ?>" class="form-control" id="exampleInputEmail3" >
        <input type="submit" class="btn btn-default" value="搜索"/>
        <input type="button" onclick="res()" value="全部显示" class="btn btn-default"/>
    </form>
</div>

<table class="table table-bordered" style="width: 1300px;margin: 0 auto">
    <tr>
        <th>请选择</th>
        <th>编号</th>
        <th>产品名称</th>
        <th>二维码</th>
        <th>视频</th>
        <th>产品介绍</th>
        <th>分类</th>
        <th>进货价</th>
        <th>统一零售价</th>
        <th>合作模式</th>
        <!--<th>状态</th>-->
        <th>操作</th>
    </tr>
    {foreach $result as $val}
    <tr id="del{$val.id}" style="text-align: center">
        <td><input type="checkbox" name="check" value="{$val.id}"/></td>
        <td>{$val.id}</td>
        <td style="width: 150px">{$val.pname}</td>
        <td><img src="__ROOT__\{$val.code}" width="50" height="50"></td>
        <td><a href="{:url('index/shelves/preview')}?id={$val.id}">{$val.video|substr=###,0,10}</a></td>
        <td style="width: 200px" >{$val.introduce|substr=###,0,20}</td>
        <td>{$val.category}</td>
        <td>{$val.purchaseprice}元</td>
        <td>{$val.retailprice}元</td>
        <td>{if $val.cooperation == 1} 进货价采购 {else/} 少量货物月结 {/if}</td>
        <!--<td>{if $val.status == 1} 审核通过 {elseif $val.status == 3 /} 审核中 {elseif $val.status == 6/} 内容制作中 {elseif $val.status == 7/}已上架{/if}</td>-->
        <td>
            <button onclick="del({$val.id})" type="button" class="btn btn-danger btn-xs">删除</button>
            <button onclick="picture({$val.id})" type="button" class="btn btn-primary btn-xs" >查看图片</button>
        </td>
    </tr>
    {/foreach}
</table>
<div style="margin-left: 30px">{$result->render()}</div>
</body>
<script>
    //显示全部
    function res() {
        var id = $('input[name="id"]').val();
        window.location.href = "{:url('index/order/goods')}?id="+id;
    }
    //删除商品
    function del(id) {
        layer.confirm('你确定要删除吗',{bnt:['确定','取消']},
            function () {
                $.ajax({
                    url:"{:url('index/order/goodsDel')}",
                    type:"post",
                    data:"id="+id,
                    dataType:"json",
                    success:function (data) {
                        if(data.success){
                            layer.alert(data.success);
                            $("#del"+id).remove();
                        }
                        if(data.error){
                            layer.alert(data.error);
                        }
                    }
                });
            }
        );
    }
    //查看图片
    function picture(id) {
        window.location.href = "{:url('index/examine/image')}?id="+id;
    }

    //采购申请
    function purchase(bid) {
        var id =[];//定义一个数组
        $('input[name="check"]:checked').each(function(){
            id.push($(this).val());
        });
        if(id.length == 0){
            layer.alert('请选择要采购的商品');
            return;
        }
        window.location.href= "{:url('index/order/purchase')}?id="+id+"&bid="+bid;
    }

    //添加商品
    function product(bid) {
        window.location.href = "{:url('index/product/add')}?bid="+bid;
    }
</script>
</html>